home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2006 May / PCWMAY06.iso / Software / Freeware / First Page 2006 3.00 / fp2006-final-3.00-setup.exe / {app} / Iscripts / Forms Misc / format-phone-numebrs.izs < prev    next >
Text File  |  2005-09-28  |  5KB  |  267 lines

  1. <!NOWIZARD>
  2.  
  3. <!TITLE>Format Phone Number
  4. <!/TITLE>
  5.  
  6. <!DESCRIPTION>This script will format a telephone number entered into a text box. Numbers can be entered as 1234567890 and will automatically be formatted as (123)456-7890. <!/DESCRIPTION> 
  7.  
  8. <!CATEGORY>Forms<!/CATEGORY>
  9.  
  10. <!SCRIPT>
  11. <!-- START OF SCRIPT -->
  12.  
  13. <!-- HOW TO INSTALL FORMAT PHONE NUMBER:
  14.  
  15.   1.  Copy code into the HEAD section of document
  16.   2.  Put last coding into the BODY section of document  -->
  17.  
  18. <!-- STEP ONE: Add code into HEAD section of document  -->
  19.  
  20. <HEAD>
  21.  
  22. <SCRIPT LANGUAGE="JavaScript">
  23.  
  24.  
  25. <!-- Original:  Roman Feldblum (web.developer@programmer.net) -->
  26.  
  27. <!-- Begin
  28. var n;
  29. var p;
  30. var p1;
  31. function ValidatePhone(){
  32. p=p1.value
  33. if(p.length==3){
  34.     //d10=p.indexOf('(')
  35.     pp=p;
  36.     d4=p.indexOf('(')
  37.     d5=p.indexOf(')')
  38.     if(d4==-1){
  39.         pp="("+pp;
  40.     }
  41.     if(d5==-1){
  42.         pp=pp+")";
  43.     }
  44.     //pp="("+pp+")";
  45.     document.frmPhone.txtphone.value="";
  46.     document.frmPhone.txtphone.value=pp;
  47. }
  48. if(p.length>3){
  49.     d1=p.indexOf('(')
  50.     d2=p.indexOf(')')
  51.     if (d2==-1){
  52.         l30=p.length;
  53.         p30=p.substring(0,4);
  54.         //alert(p30);
  55.         p30=p30+")"
  56.         p31=p.substring(4,l30);
  57.         pp=p30+p31;
  58.         //alert(p31);
  59.         document.frmPhone.txtphone.value="";
  60.         document.frmPhone.txtphone.value=pp;
  61.     }
  62.     }
  63. if(p.length>5){
  64.     p11=p.substring(d1+1,d2);
  65.     if(p11.length>3){
  66.     p12=p11;
  67.     l12=p12.length;
  68.     l15=p.length
  69.     //l12=l12-3
  70.     p13=p11.substring(0,3);
  71.     p14=p11.substring(3,l12);
  72.     p15=p.substring(d2+1,l15);
  73.     document.frmPhone.txtphone.value="";
  74.     pp="("+p13+")"+p14+p15;
  75.     document.frmPhone.txtphone.value=pp;
  76.     //obj1.value="";
  77.     //obj1.value=pp;
  78.     }
  79.     l16=p.length;
  80.     p16=p.substring(d2+1,l16);
  81.     l17=p16.length;
  82.     if(l17>3&&p16.indexOf('-')==-1){
  83.         p17=p.substring(d2+1,d2+4);
  84.         p18=p.substring(d2+4,l16);
  85.         p19=p.substring(0,d2+1);
  86.         //alert(p19);
  87.     pp=p19+p17+"-"+p18;
  88.     document.frmPhone.txtphone.value="";
  89.     document.frmPhone.txtphone.value=pp;
  90.     //obj1.value="";
  91.     //obj1.value=pp;
  92.     }
  93. }
  94. //}
  95. setTimeout(ValidatePhone,100)
  96. }
  97. function getIt(m){
  98. n=m.name;
  99. //p1=document.forms[0].elements[n]
  100. p1=m
  101. ValidatePhone()
  102. }
  103. function testphone(obj1){
  104. p=obj1.value
  105. //alert(p)
  106. p=p.replace("(","")
  107. p=p.replace(")","")
  108. p=p.replace("-","")
  109. p=p.replace("-","")
  110. //alert(isNaN(p))
  111. if (isNaN(p)==true){
  112. alert("Check phone");
  113. return false;
  114. }
  115. }
  116. //  End -->
  117. </script>
  118.  
  119. </HEAD>
  120.  
  121. <!-- STEP TWO: Add code into BODY section of document  -->
  122.  
  123. <BODY>
  124.  
  125. <div align="center">
  126. <form name=frmPhone>
  127. <font size="4" color="#0000FF"><b>Enter Telephone Number</b></font><br>
  128. (To refresh, hold down shift and press the browser refresh button)<br>
  129. <input type=text name=txtphone maxlength="13" onclick="javascript:getIt(this)" >
  130. </form>
  131. </div>
  132.  
  133.  
  134.  
  135. <!-- END OF SCRIPT -->
  136. <!/SCRIPT>
  137.  
  138. <!PREVIEW>
  139. <!-- START OF SCRIPT -->
  140.  
  141. <!-- HOW TO INSTALL FORMAT PHONE NUMBER:
  142.  
  143.   1.  Copy code into the HEAD section of document
  144.   2.  Put last coding into the BODY section of document  -->
  145.  
  146. <!-- STEP ONE: Add code into HEAD section of document  -->
  147.  
  148. <HEAD>
  149.  
  150. <SCRIPT LANGUAGE="JavaScript">
  151.  
  152.  
  153. <!-- Original:  Roman Feldblum (web.developer@programmer.net) -->
  154.  
  155. <!-- Begin
  156. var n;
  157. var p;
  158. var p1;
  159. function ValidatePhone(){
  160. p=p1.value
  161. if(p.length==3){
  162.     //d10=p.indexOf('(')
  163.     pp=p;
  164.     d4=p.indexOf('(')
  165.     d5=p.indexOf(')')
  166.     if(d4==-1){
  167.         pp="("+pp;
  168.     }
  169.     if(d5==-1){
  170.         pp=pp+")";
  171.     }
  172.     //pp="("+pp+")";
  173.     document.frmPhone.txtphone.value="";
  174.     document.frmPhone.txtphone.value=pp;
  175. }
  176. if(p.length>3){
  177.     d1=p.indexOf('(')
  178.     d2=p.indexOf(')')
  179.     if (d2==-1){
  180.         l30=p.length;
  181.         p30=p.substring(0,4);
  182.         //alert(p30);
  183.         p30=p30+")"
  184.         p31=p.substring(4,l30);
  185.         pp=p30+p31;
  186.         //alert(p31);
  187.         document.frmPhone.txtphone.value="";
  188.         document.frmPhone.txtphone.value=pp;
  189.     }
  190.     }
  191. if(p.length>5){
  192.     p11=p.substring(d1+1,d2);
  193.     if(p11.length>3){
  194.     p12=p11;
  195.     l12=p12.length;
  196.     l15=p.length
  197.     //l12=l12-3
  198.     p13=p11.substring(0,3);
  199.     p14=p11.substring(3,l12);
  200.     p15=p.substring(d2+1,l15);
  201.     document.frmPhone.txtphone.value="";
  202.     pp="("+p13+")"+p14+p15;
  203.     document.frmPhone.txtphone.value=pp;
  204.     //obj1.value="";
  205.     //obj1.value=pp;
  206.     }
  207.     l16=p.length;
  208.     p16=p.substring(d2+1,l16);
  209.     l17=p16.length;
  210.     if(l17>3&&p16.indexOf('-')==-1){
  211.         p17=p.substring(d2+1,d2+4);
  212.         p18=p.substring(d2+4,l16);
  213.         p19=p.substring(0,d2+1);
  214.         //alert(p19);
  215.     pp=p19+p17+"-"+p18;
  216.     document.frmPhone.txtphone.value="";
  217.     document.frmPhone.txtphone.value=pp;
  218.     //obj1.value="";
  219.     //obj1.value=pp;
  220.     }
  221. }
  222. //}
  223. setTimeout(ValidatePhone,100)
  224. }
  225. function getIt(m){
  226. n=m.name;
  227. //p1=document.forms[0].elements[n]
  228. p1=m
  229. ValidatePhone()
  230. }
  231. function testphone(obj1){
  232. p=obj1.value
  233. //alert(p)
  234. p=p.replace("(","")
  235. p=p.replace(")","")
  236. p=p.replace("-","")
  237. p=p.replace("-","")
  238. //alert(isNaN(p))
  239. if (isNaN(p)==true){
  240. alert("Check phone");
  241. return false;
  242. }
  243. }
  244. //  End -->
  245. </script>
  246.  
  247. </HEAD>
  248.  
  249. <!-- STEP TWO: Add code into BODY section of document  -->
  250.  
  251. <BODY>
  252.  
  253. <div align="center">
  254. <form name=frmPhone>
  255. <font size="4" color="#0000FF"><b>Enter Telephone Number</b></font><br>
  256. (To refresh, hold down shift and press the browser refresh button)<br>
  257. <input type=text name=txtphone maxlength="13" onclick="javascript:getIt(this)" >
  258. </form>
  259. </div>
  260.  
  261.  
  262.  
  263. <!-- END OF SCRIPT -->
  264. <!/PREVIEW>
  265.  
  266. <!RELATED>NONE<!/RELATED>
  267.